import http from '@/libs/http'

// 航班基础信息相关API
export default {
  // 航班基础信息
  getFlightBaseList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/flightBase/page', { params: queryParams })
  },
  
  getFlightBaseById(id: number) {
    return http.get(`/flightBase/${id}`)
  },
  
  createFlightBase(data: any) {
    return http.post('/flightBase', data)
  },
  
  updateFlightBase(data: any) {
    return http.put('/flightBase', data)
  },
  
  deleteFlightBase(id: number) {
    return http.delete(`/flightBase/${id}`)
  },
  
  deleteBatchFlightBase(ids: number[]) {
    return http.delete('/flightBase/batch', { data: ids })
  },

  // 航班动态信息
  getFlightDynamicList(params: any) {
    return http.get('/api/test/flight-dynamic', { params })
  },

  // 值机柜台显示信息
  getCheckinDisplayList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/checkinDisplay/page', { params: queryParams })
  },
  
  getCheckinDisplayById(id: number) {
    return http.get(`/checkinDisplay/${id}`)
  },
  
  createCheckinDisplay(data: any) {
    return http.post('/checkinDisplay', data)
  },
  
  updateCheckinDisplay(data: any) {
    return http.put('/checkinDisplay', data)
  },
  
  deleteCheckinDisplay(id: number) {
    return http.delete(`/checkinDisplay/${id}`)
  },

  deleteBatchCheckinDisplay(ids: number[]) {
    return http.delete('/checkinDisplay/batch', { data: ids })
  },

  // 航班资源分配
  getFlightResourcesList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/flightResources/page', { params: queryParams })
  },
  
  getFlightResourcesById(id: number) {
    return http.get(`/flightResources/${id}`)
  },
  
  createFlightResources(data: any) {
    return http.post('/flightResources', data)
  },
  
  updateFlightResources(data: any) {
    return http.put('/flightResources', data)
  },
  
  deleteFlightResources(id: number) {
    return http.delete(`/flightResources/${id}`)
  },

  deleteBatchFlightResources(ids: number[]) {
    return http.delete('/flightResources/batch', { data: ids })
  },

  // 航班航线信息
  getFlightRouteList(params: any) {
    return http.get('/flightRoute/page', { params })
  },
  
  getFlightRouteById(id: number) {
    return http.get(`/flightRoute/${id}`)
  },
  
  createFlightRoute(data: any) {
    return http.post('/flightRoute', data)
  },
  
  updateFlightRoute(data: any) {
    return http.put('/flightRoute', data)
  },
  
  deleteFlightRoute(id: number) {
    return http.delete(`/flightRoute/${id}`)
  },

  deleteBatchFlightRoute(ids: number[]) {
    return http.delete('/flightRoute/batch', { data: ids })
  },

  // 航班动态状态
  getFlightStatusList(params: any) {
    return http.get('/flightStatus/page', { params })
  },
  
  getFlightStatusById(id: number) {
    return http.get(`/flightStatus/${id}`)
  },
  
  createFlightStatus(data: any) {
    return http.post('/flightStatus', data)
  },
  
  updateFlightStatus(data: any) {
    return http.put('/flightStatus', data)
  },
  
  deleteFlightStatus(id: number) {
    return http.delete(`/flightStatus/${id}`)
  },

  deleteBatchFlightStatus(ids: number[]) {
    return http.delete('/flightStatus/batch', { data: ids })
  },

  // 航班时间信息
  getFlightTimesList(params: any) {
    return http.get('/flightTimes/page', { params })
  },
  
  getFlightTimesById(id: number) {
    return http.get(`/flightTimes/${id}`)
  },
  
  createFlightTimes(data: any) {
    return http.post('/flightTimes', data)
  },
  
  updateFlightTimes(data: any) {
    return http.put('/flightTimes', data)
  },
  
  deleteFlightTimes(id: number) {
    return http.delete(`/flightTimes/${id}`)
  },

  deleteBatchFlightTimes(ids: number[]) {
    return http.delete('/flightTimes/batch', { data: ids })
  },

  // 共享航班信息
  getSharedFlightsList(params: any) {
    return http.get('/sharedFlights/page', { params })
  },
  
  getSharedFlightsById(id: number) {
    return http.get(`/sharedFlights/${id}`)
  },
  
  createSharedFlights(data: any) {
    return http.post('/sharedFlights', data)
  },
  
  updateSharedFlights(data: any) {
    return http.put('/sharedFlights', data)
  },
  
  deleteSharedFlights(id: number) {
    return http.delete(`/sharedFlights/${id}`)
  },

  deleteBatchSharedFlights(ids: number[]) {
    return http.delete('/sharedFlights/batch', { data: ids })
  },

  // 特殊操作消息
  getSpecialMessagesList(params: any) {
    return http.get('/specialMessages/page', { params })
  },
  
  getSpecialMessagesById(id: number) {
    return http.get(`/specialMessages/${id}`)
  },
  
  createSpecialMessages(data: any) {
    return http.post('/specialMessages', data)
  },
  
  updateSpecialMessages(data: any) {
    return http.put('/specialMessages', data)
  },
  
  deleteSpecialMessages(id: number) {
    return http.delete(`/specialMessages/${id}`)
  },

  deleteBatchSpecialMessages(ids: number[]) {
    return http.delete('/specialMessages/batch', { data: ids })
  },

  // 航班飞机信息
  getFlightInfoList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/api/flightInfo/list', { params: queryParams })
  },

  createFlightInfo(data: any) {
    return http.post('/api/flightInfo', data)
  },

  updateFlightInfo(data: any) {
    return http.put('/api/flightInfo', data)
  },

  deleteFlightInfo(id: number) {
    return http.delete(`/api/flightInfo/${id}`)
  },

  // 登机门分配
  getGateAssignmentList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/gateAssignment/page', { params: queryParams })
  },

  // 机位分配
  getStandAssignmentList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/standAssignment/page', { params: queryParams })
  },

  // 行李转盘分配
  getBeltAssignmentList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/beltAssignment/page', { params: queryParams })
  }
}

// 航班基础信息具名导出
export const getFlightBasePage = (params: any) => {
  return http.get('/flightBase/page', { params })
}

export const getFlightBaseById = (id: number) => {
  return http.get(`/flightBase/${id}`)
}

export const addFlightBase = (data: any) => {
  return http.post('/flightBase', data)
}

export const updateFlightBase = (data: any) => {
  return http.put('/flightBase', data)
}

export const deleteFlightBase = (id: number) => {
  return http.delete(`/flightBase/${id}`)
}

export const deleteBatchFlightBase = (ids: number[]) => {
  return http.delete('/flightBase/batch', { data: ids })
}

// 机场信息API
export const airportApi = {
  getAirportInfoList(params: any) {
    // 转换参数名称：pageNo -> current, pageSize -> size
    const queryParams = { ...params }
    if (queryParams.pageNo) {
      queryParams.current = queryParams.pageNo
      delete queryParams.pageNo
    }
    if (queryParams.pageSize) {
      queryParams.size = queryParams.pageSize
      delete queryParams.pageSize
    }
    return http.get('/airportInfo/page', { params: queryParams })
  },
  
  getAirportInfoById(id: number) {
    return http.get(`/airportInfo/${id}`)
  },
  
  createAirportInfo(data: any) {
    return http.post('/airportInfo', data)
  },
  
  updateAirportInfo(data: any) {
    return http.put('/airportInfo', data)
  },
  
  deleteAirportInfo(id: number) {
    return http.delete(`/airportInfo/${id}`)
  }
}

// XML导入API
export const xmlApi = {
  importAllXml() {
    return http.post('/api/xml/import-all')
  },
  
  importByType(messageType: string) {
    return http.post('/api/xml/import-by-type', null, {
      params: { messageType }
    })
  },
  
  uploadXmlFile(file: File) {
    const formData = new FormData()
    formData.append('file', file)
    return http.post('/api/xml/upload', formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },
  
  importFromPath(xmlFolderPath: string) {
    return http.post('/api/xml/import-from-path', null, {
      params: { xmlFolderPath }
    })
  },
  
  getMessageTypes() {
    return http.get('/api/xml/message-types')
  },
  
  clearAllData() {
    return http.delete('/api/xml/clear-all')
  },
  
  getImportStats() {
    return http.get('/api/xml/stats')
  }
}

// 系统测试API
export const testApi = {
  getSystemStatus() {
    return http.get('/api/test/status')
  },
  
  getDataStats() {
    return http.get('/api/test/data-stats')
  },
  
  getMsgMeta(limit = 10) {
    return http.get('/api/test/msg-meta', { params: { limit } })
  },
  
  testDbConnection() {
    return http.get('/api/test/db-connection')
  },
  
  clearTestData() {
    return http.delete('/api/test/clear-test-data')
  }
} 